#include <stdio.h>
#include <stdlib.h>


struct ex
{
  	int num;
    char name[50];
   
};

int cmp1(const void* a, const void* b)
{
    return (*(int*)a - *(int*)b);
    
}

int cmp2(const void* a, const void* b )
{
    struct ex x = *(struct ex*) a;
    struct ex y = *(struct ex*) b;
    
    
    
 	return (x.num - y.num);   
}


int main()
{
    int a[] = {2, 3, 5, 54, 56, 54, 99, 123};
    
    struct ex ee;
    struct ex example[] = {{25, "雪糕"},{4, "可乐"},{88, "火锅"},{12, "电池"},{288, "脑白金"}};
    
    printf("整形数组排序如下\n");
    
    qsort(a, sizeof(a) / sizeof(int), sizeof(int), cmp1);
    
    for(int x = 0; x < sizeof(a) / sizeof(int); x++)
    {
        printf("%d \n", a[x]);
    }
    
    printf("结构体数组排序如下\n");
    
    qsort(example, sizeof(example) / sizeof(ee), sizeof(ee), cmp2);
    
    for(int y = 0; y < sizeof(example) / sizeof(ee); y++)
    {
        printf("%d %s \n", example[y].num, example[y].name);
    } 
    
    return 0;
}
    